﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections.ObjectModel;
using University.Workshop.Business;

namespace University.Workshop.WinApp
{
    public partial class GraficProductReport : Form
    {
        public Collection<string> listname = new Collection<string>();
        public Collection<String> listcant = new Collection<string>();

        public GraficProductReport()
        {
            InitializeComponent();
            GenerateQuery();
        }

        private void GenerateQuery()
        {
            listname = ProductController.GenerateQuery1GetName();
            listcant = ProductController.GenerateQueryGetQuantity();
            GraficAnalysisReport(listcant, listname);
        }
        public void GraficAnalysisReport(Collection<string> component, Collection<string> componentOne)
        {

            double[] aux = new double[component.Count];
            int i = 0;
            foreach (string aux1 in component)
            {
                aux[i] = Convert.ToDouble(aux1, System.Globalization.CultureInfo.CurrentCulture);
                i++;
            }
            double[] yValues = aux;
            string[] xNames = new string[componentOne.Count];
            i = 0;
            foreach (string aux1 in componentOne)
            {
                xNames[i] = aux1;
                i++;
            }
            chartGraficReportProduct.Series[0].Points.DataBindXY(xNames, yValues);
        }

        private void GraficProductReport_Load(object sender, EventArgs e)
        {
            try
            {
                listname = ProductController.GenerateQuery1GetName();
                listcant = ProductController.GenerateQueryGetQuantity();
                GraficAnalysisReport(listcant, listname);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void buttonExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonExitReportGrafic_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
